<?php
  
  //include "sessions.php";
  require 'libs/3rd_php/QDServiceLocator.php';
  require 'libs/3rd_php/QDSvc.php';
  function url_exists($url){
        if(!strstr($url, "http://")) { $url = "http://".$url; };
     $fp = @fsockopen($url, 80);
     if($fp === false) { return 'false'; } else { return true; };
  }
  function db($v){
    print '<pre>';
    print_r($v);
    print '</pre>';
  }
  /**
   * Return human readable sizes
   *
   * @author      Aidan Lister <aidan@php.net>
   * @version     1.2.0
   * @link        http://aidanlister.com/repos/v/function.size_readable.php
   * @param       int     $size        size in bytes
   * @param       string  $max         maximum unit
   * @param       bool    $si          use SI (1000) prefixes
   * @param       string  $retstring   return string format
   */
  function size_readable($size, $max = null, $si = true, $retstring = '%01.2f %s'){
      // Pick units
      if ($si === true) {
          $sizes = array('B', 'K', 'MB', 'GB', 'TB', 'PB');
          $mod   = 1000;
      } else {
          $sizes = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB');
          $mod   = 1024;
      }
   
      // Max unit to display
      if ($max && false !== $d = array_search($max, $sizes)) {
          $depth = $d;
      } else {
          $depth = count($sizes) - 1;
      }
   
      // Loop
      $i = 0;
      while ($size >= 1024 && $i < $depth) {
          $size /= $mod;
          $i++;
      }
   
      return sprintf($retstring, $size, $sizes[$i]);
  }
    function myjson($s){
      if(is_numeric($s)) return $s;
      if(is_string($s)) return preg_replace("@([\1-\037])@e",
       "sprintf('\\\\u%04X',ord('$1'))",
        str_replace("\0", '\u0000',
        utf8_decode(json_encode(utf8_encode($s))))); 
      if($s===false) return 'false';
      if($s===true) return 'true';
      if(is_array($s))
      {
        $c=0;
        foreach($s as $k=>&$v)
          if($k !== $c++)
          {
            foreach($s as $k=>&$v) $v = myjson((string)$k).':'.myjson($v);
            return '{'.join(',', $s).'}';
          }
        return '[' . join(',', array_map('myjson', $s)) . ']';
      }
      return 'null';
    } 
  function object2array($object){
      $return = NULL;
      if(is_array($object)){
          foreach($object as $key => $value)
              $return[$key] = object2array($value);
      }else{
          $var = get_object_vars($object);          
          if($var){
              foreach($var as $key => $value)
                  $return[$key] = ($key && !$value) ? NULL : object2array($value);
          }
          else return $object;
      }
      return $return;
  }
	
?>